﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="insert.aspx.cs" Inherits="WebApplication1.insert" %>

<%@ Register src="include/userInsert.ascx" tagname="userInsert" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="css/popupInsert.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        //========================= Load Phuong ========================================
        $().ready(function () {
            $.ajax({
                type: "GET",
                url: "http://localhost:49732/Service.svc/phuong",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var list = data;

                    for (var i = 0; i < list.length; i++) {
                        var combo = document.getElementById("cbbPhuong");
                        var option = document.createElement("option");
                        option.text = data[i].TenPhuong.toString();
                        option.value = data[i].MaPhuong.toString();
                        try {
                             combo.add(option, null);
                        }
                        catch (Error) {
                            alert("Co loi");
                            combo.add(option);
                        }
                    }
                },
                error: function () {
                    alert("Failed to load genders");
                }
            });
        });
        //================================= End Load =================================== 
        //========================= Load TinhThanh  ========================================
        $().ready(function () {
            $.ajax({
                type: "GET",
                url: "http://localhost:49732/Service.svc/tinhthanh",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var list = data;

                    for (var i = 0; i < list.length; i++) {
                        var combo = document.getElementById("cbbTinhThanh");
                        var option = document.createElement("option");
                        option.text = data[i].TenTinhThanh.toString();
                        option.value = data[i].MaTinhThanh.toString();
                        try {
                            combo.add(option, null);
                        }
                        catch (Error) {
                            alert("Co loi");
                            combo.add(option);
                        }
                    }
                },
                error: function () {
                    alert("Failed to load genders");
                }
            });
        });
        //================================= End Load =================================== 
        //========================= Load Phuong ========================================
        $().ready(function () {
            $.ajax({
                type: "GET",
                url: "http://localhost:49732/Service.svc/dichvu",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var list = data;

                    for (var i = 0; i < list.length; i++) {
                        var combo = document.getElementById("cbbDichVu");
                        var option = document.createElement("option");
                        option.text = data[i].TenDichVu.toString();
                        option.value = data[i].MaDichVu.toString();
                        try {
                            combo.add(option, null);
                        }
                        catch (Error) {
                            alert("Co loi");
                            combo.add(option);
                        }
                    }
                },
                error: function () {
                    alert("Failed to load genders");
                }
            });
        });
        //================================= End Load =================================== 
        
        //========================= Load Quận Huyện ========================================
        $().ready(function () {
            $.ajax({
                type: "GET",
                url: "http://localhost:49732/Service.svc/quanhuyen",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var list = data;

                    for (var i = 0; i < list.length; i++) {
                        var combo = document.getElementById("cbbQuanHuyen");
                        var option = document.createElement("option");
                        option.text = data[i]._tenQuanHuyen.toString();
                        option.value = data[i]._maQuanHuyen.toString();
                        try {
                            combo.add(option, null);
                        }
                        catch (Error) {
                            alert("Co loi");
                            combo.add(option);
                        }
                    }
                },
                error: function () {
                    alert("Failed to load genders");
                }
            });
        });
        //================================= End Load ===================================   
        /*=================================Insert========================================*/
        $(document).ready(function () {
            $("#btnThem").click(function () {
                var data = '{"TenDuLieu":"' + $("#txtTenDichVu").val() + '","SoNha":"' + $("#txtSoNha").val();
                data = data + '","TenDuong":"' + $("#txtPhuong").val() + '","MaPhuong":"' + $("#cbbPhuong").val();
                data = data + '","MaQuanHuyen":"' + $("#cbbQuanHuyen").val() + '","MaTinhThanh":"' + $("#cbbTinhThanh"), val();
                data = data + '","MaDichVu":"' + $("#cbbDichVu").val() + '"}';
                $.ajax({
                    type:"POST",
                    url: "http://localhost:49732/Service.svc/dulieu",
                    data:data,
                    contentType:"application/json; charset=utf-8",
                    datType: "json",
                    success: insertCallback
                });
            });
        });

        function insrtCallback(result) {
            result = result["d"];
            if (result == true) {
                alert("Them Thanh Cong");
            } else {
                alert("Them That Bai");
            }
        }
        /*=================================  End ========================================*/
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="frame_insert">   
        <div id="popupContactClose"><a href="#">Close</a> </div>
             <uc1:userInsert ID="userInsert1" runat="server" />
        <div id="backgroundPopup"></div>
    </div>
    </form>
</body>
</html>
